(function(){"use strict";BX.namespace("BX.Landing.UI.Panel");var e=BX.Landing.Utils.addClass;var t=BX.Landing.Utils.removeClass;var n=BX.Landing.Utils.append;var i=BX.Landing.Utils.onCustomEvent;var a=BX.Landing.Utils.setTextContent;var r=BX.Landing.Utils.create;var s=BX.Landing.Utils.style;var o=BX.Landing.Utils.isNumber;var d=BX.Landing.Utils.isString;var c=BX.Landing.Utils.isPlainObject;var l=BX.Landing.Utils.isArray;var h=BX.Landing.Utils.addQueryParams;var u="landing";var g="block";var L="system";var f="crmFormPopup";var p="crmPhone";var I="user";var v=BX.Landing.UI.Button.SidebarButton;BX.Landing.UI.Panel.URLList=function(t,a){BX.Landing.UI.Panel.Content.apply(this,arguments);e(this.layout,"landing-ui-panel-url-list");e(this.overlay,"landing-ui-panel-url-list-overlay");e(this.overlay,"landing-ui-hide");this.overlay.hidden=true;this.overlay.dataset.isShown="false";i("BX.Landing.Block:init",this.refresh.bind(this));i("BX.Landing.Block:remove",this.refresh.bind(this));if(BX.Landing.Main.isEditorMode()){n(this.layout,window.parent.document.body)}else{this.overlay.parentNode.removeChild(this.overlay);document.body.appendChild(this.overlay);n(this.layout,document.body);this.layout.style.marginTop=0;this.overlay.style.marginTop=0}this.loader=new BX.Loader({target:this.content});this.promiseResolve=function(){};this.layout.hidden=true;this.isNeedLoad=true;this.cache=new BX.Cache.MemoryCache};BX.Landing.UI.Panel.URLList.getInstance=function(){if(!BX.Landing.UI.Panel.URLList.instance){BX.Landing.UI.Panel.URLList.instance=new BX.Landing.UI.Panel.URLList("url_list")}return BX.Landing.UI.Panel.URLList.instance};BX.Landing.UI.Panel.URLList.instance=null;BX.Landing.UI.Panel.URLList.prototype={constructor:BX.Landing.UI.Panel.URLList,__proto__:BX.Landing.UI.Panel.Content.prototype,refresh:function(){this.isNeedLoad=true},showLoader:function(){this.loader.show(this.content)},show:function(e,n){this.showOptions=n;BX.Landing.UI.Panel.Content.prototype.show.call(this);this.clear();this.showLoader();if(e===u){t(this.layout,"landing-ui-panel-url-list-blocks");a(this.title,n.panelTitle||BX.Landing.Loc.getMessage("LANDING_LINKS_LANDINGS_TITLE"));this.showSites(n)}else if(e===g){a(this.title,n.panelTitle||BX.Landing.Loc.getMessage("LANDING_LINKS_BLOCKS_TITLE"));this.showBlocks(n)}else if(e===f){a(this.title,n.panelTitle||BX.Landing.Loc.getMessage("LANDING_LINKS_CRM_FORMS_TITLE"));this.showForms(n)}else if(e===p){a(this.title,n.panelTitle||BX.Landing.Loc.getMessage("LANDING_LINKS_CRM_PHONES_TITLE"));this.showPhones(n)}else if(e===I){a(this.title,n.panelTitle||BX.Landing.Loc.getMessage("LANDING_LINKS_CRM_PHONES_USERS"))}return new Promise(function(e){this.promiseResolve=e}.bind(this))},showSites:function(e){let t=e.siteId;void s(this.layout,{width:null});if(!BX.Type.isPlainObject(e.filter)){e.filter={}}var n=BX.Landing.Env.getInstance();if(BX.Type.isNil(e.filter.ID)&&n.getType()==="GROUP"){e.filter.ID=n.getSiteId()}if(e.filter.ID===-1){delete e.filter.ID}e.filter.SPECIAL="N";void BX.Landing.Backend.getInstance().getSites(e).then((n=>{n.forEach((n=>{if(parseInt(n.ID)==t){this.appendSidebarButton(this.createCurrentSiteButton());this.currentSiteButton=new v(n.ID,{text:n.TITLE,onClick:!e.currentSiteOnly?this.onSiteClick.bind(this,n.ID,e.enableAreas):null,child:true,active:true});this.appendSidebarButton(this.currentSiteButton)}}));if(!e.currentSiteOnly){this.appendSidebarButton(new v("my_sites",{text:BX.Landing.Loc.getMessage("LANDING_LINKS_PANEL_MY_SITES")}));n.forEach((n=>{const i=new v(n.ID,{text:n.TITLE,onClick:this.onSiteClick.bind(this,n.ID,e.enableAreas),child:true,active:!this.currentSiteButton});if(!this.currentSiteButton){this.currentSiteButton=i;t=n.ID}this.appendSidebarButton(i)}))}BX.Landing.Backend.getInstance().getLandings({siteId:t},e.filterLanding).then((n=>{const i={currentTarget:this.currentSiteButton.layout};const a=this.onSiteClick.bind(this,t,e.enableAreas,i);if(!e.disableAddPage){this.appendCard(new BX.Landing.UI.Card.AddPageCard({siteId:t,onSave:this.addPageSave.bind(this,a,t)}))}n.forEach((t=>{if(!t.IS_AREA||t.IS_AREA&&e.enableAreas){this.appendCard(new BX.Landing.UI.Card.LandingPreviewCard({title:t.TITLE,description:t.DESCRIPTION,preview:t.PREVIEW,onClick:this.onLandingClick.bind(this,t.ID,t.TITLE)}))}}));this.loader.hide()}))}))},createCurrentSiteButton:function(){return new v("current_site",{text:BX.Landing.Loc.getMessage("LANDING_LINKS_PANEL_CURRENT_SITE")})},showBlocks:function(e){var t=e.landingId;var n=e.siteId;void s(this.layout,{width:"880px"});if(!BX.Type.isPlainObject(e.filter)){e.filter={SPECIAL:"N"}}else{e.filter.SPECIAL="N"}BX.Landing.Backend.getInstance().getSites(e).then(function(e){const t=e.map((function(e){return e.ID}),this);return BX.Landing.Backend.getInstance().getLandings({siteId:t}).then((function(t){return e.reduce((function(e,n,i){const a=t.filter((function(e){return n.ID===e.SITE_ID&&!e.IS_AREA}));e[n.ID]={site:n,landings:a};return e}),{})}))}.bind(this)).then(function(i){let a=null;if(i[n]){this.appendSidebarButton(this.createCurrentSiteButton());i[n].landings.forEach((function(n){const i=parseInt(n.ID)===parseInt(t);if(!e.currentPageOnly||i){const e=this.createLandingSidebarButton(n,i);this.appendSidebarButton(e);if(i){a=e}}}),this)}if(!e.currentPageOnly){Object.keys(i).forEach((function(e){if(parseInt(e)!==parseInt(n)){var t=i[e].site;this.appendSidebarButton(this.createSiteSidebarButton(t));i[e].landings.forEach((function(e){const t=this.createLandingSidebarButton(e);this.appendSidebarButton(t);if(!a){a=t}}),this)}}),this)}if(a){a.layout.click()}}.bind(this))},showForms:function(){void s(this.layout,{width:"500px"});BX.Landing.Backend.getInstance().action("Form::getList").then(function(e){e.forEach(function(e){var t={title:e.NAME,className:"landing-ui-card-form-preview",onClick:this.onFormChange.bind(this,e)};if(e.IS_CALLBACK_FORM==="Y"){t.className+=" landing-ui-card-form-preview--callback"}this.appendCard(new BX.Landing.UI.Card.BaseCard(t))}.bind(this));this.loader.hide()}.bind(this))},onFormChange:function(e){this.hide();this.promiseResolve({id:e.ID,type:"crmFormPopup",name:e.NAME})},showPhones:function(){void s(this.layout,{width:"500px"});BX.Landing.Env.getInstance().getOptions().references.forEach(function(e){this.appendCard(new BX.Landing.UI.Card.BaseCard({title:e.text,className:"landing-ui-card-form-preview",onClick:this.onPhoneChange.bind(this,e)}))}.bind(this));this.loader.hide()},onPhoneChange:function(e){this.hide();this.promiseResolve({id:e.value,type:"crmPhone",name:e.text})},createLandingSidebarButton:function(e,t){return new v(e.ID,{text:e.TITLE,onClick:this.onLandingChange.bind(this,e),child:true,active:t})},createSiteSidebarButton:function(e){return new v(e.ID,{text:e.TITLE,child:false,active:false})},onLandingChange:function(e,t){this.currentSelectedLanding=e;this.sidebarButtons.forEach((function(e){if(e.layout===t.currentTarget){e.activate();return}e.deactivate()}));this.showPreviewLoader().then(this.createIframeIfNeed()).then(this.loadPreviewSrc(this.buildLandingPreviewUrl(e))).then(this.hidePreviewLoader())},buildLandingPreviewUrl:function(e){var t=BX.Landing.Main.getInstance().options.params.sef_url.landing_view;t=t.replace("#site_show#",e.SITE_ID);t=t.replace("#landing_edit#",e.ID);return h(t,{landing_mode:"edit"})},loadPreviewSrc:function(e){return function(){return new Promise(function(t){if(this.previewFrame.src!==e){this.previewFrame.src=e;this.previewFrame.onload=function(){var e=this.previewFrame.contentDocument;BX.Landing.Utils.removePanels(e);[].slice.call(e.querySelectorAll(".landing-main .block-wrapper")).forEach((function(e){e.setAttribute("data-selectable",1);e.classList.add("landing-ui-block-selectable-overlay");e.addEventListener("click",function(t){t.preventDefault();var n=e.closest("[data-landing]");var i=BX.Dom.attr(n,"data-landing");this.onBlockClick(parseInt(e.id.replace("block","")),t,i)}.bind(this))}),this);[].slice.call(e.querySelectorAll(".block-wrapper")).forEach((function(e){if(!e.getAttribute("data-selectable")){e.style.display="none"}}),this);[].slice.call(e.querySelectorAll(".landing-empty")).forEach((function(e){e.style.display="none"}),this);t(this.previewFrame)}.bind(this);return}t(this.previewFrame)}.bind(this))}.bind(this)},showPreviewLoader:function(){if(!this.loader){this.loader=new BX.Loader}if(this.previewFrameWrapper){void s(this.previewFrameWrapper,{opacity:0})}return new Promise(function(e){void this.loader.show(this.content);e()}.bind(this))},hidePreviewLoader:function(){return function(){void s(this.previewFrameWrapper,{opacity:null});return this.loader.hide()}.bind(this)},createIframeIfNeed:function(){return function(){new Promise(function(e){if(!this.previewFrame){this.previewFrame=r("iframe",{});this.previewFrameWrapper=r("div",{attrs:{style:"width: 100%; height: 100%; overflow: hidden;"}});this.previewFrameWrapper.appendChild(this.previewFrame);this.content.innerHTML="";this.content.appendChild(this.previewFrameWrapper);this.showPreviewLoader();requestAnimationFrame(function(){var e=this.content.clientWidth-40;void s(this.previewFrame,{width:"1000px",height:"calc((100vh - 113px) * (100 / "+e/1e3*100+"))",transform:"scale("+e/1e3+") translateZ(0)","transform-origin":"top left",border:"none"})}.bind(this))}e(this.previewFrame)}.bind(this))}.bind(this)},onBlockClick:function(e,t,n){if(t.isTrusted){void BX.Landing.Backend.getInstance().getBlocks({landingId:n}).then(function(t){var n=t.find((function(t){return t.id===e}));if(n){this.onChange({type:g,id:n.id,name:n.name,alias:n.alias})}}.bind(this))}},onLandingClick:function(e,t){this.onChange({type:u,id:e,name:t})},onSystemClick:function(e,t){this.onChange({type:L,id:"_"+e,name:t})},onSiteClick:function(e,t,n){this.sidebarButtons.forEach((function(e){if(e.layout===n.currentTarget||!!n.target&&e.layout===n.target.closest(".landing-ui-button")){this.currentSiteButton=e;e.activate()}else{e.deactivate()}}),this);this.content.innerHTML="";this.showLoader();BX.Landing.Backend.getInstance().getLandings({siteId:e}).then(function(i){var a=this.onSiteClick.bind(this,e,t,n);this.appendCard(new BX.Landing.UI.Card.AddPageCard({siteId:e,onSave:this.addPageSave.bind(this,a,e)}));i.forEach((function(e){if(!e.IS_AREA||e.IS_AREA&&t){this.appendCard(this.createLandingPreview(e))}}),this);this.loader.hide()}.bind(this))},addPageSave:function(e,t){this.cache=new BX.Cache.MemoryCache;var n=BX.Landing.Backend.getInstance();n.cache.delete("landings+["+t+"]");n.cache.delete('landings+["'+t+'"]');n.cache.delete("landing+"+t);e()},createLandingPreview:function(e){return new BX.Landing.UI.Card.LandingPreviewCard({title:e.TITLE,description:e.DESCRIPTION,preview:e.PREVIEW,onClick:this.onLandingClick.bind(this,e.ID,e.TITLE)})},createBlockPreview:function(e){return new BX.Landing.UI.Card.BlockHTMLPreview({content:e.id,onClick:this.onBlockClick.bind(this,e.id,e.name,e.alias)})},getLanding:function(e,t){var n=JSON.stringify(["getLanding"+e,t]);return this.cache.remember(n,function(){return BX.Landing.Backend.getInstance().action("Landing::getList",{params:{filter:{ID:e},get_preview:true}}).then(function(e){return e}.bind(this))}.bind(this))},getBlock:function(e){var t="getBlocks"+e;return this.cache.remember(t,function(){return BX.Landing.Backend.getInstance().action("Block::getById",{block:e,params:{edit_mode:true}}).then(function(e){return e}.bind(this))}.bind(this))},onChange:function(e){this.promiseResolve(e);this.hide()},hide:function(){this.previewFrame=null;return BX.Landing.UI.Panel.Content.prototype.hide.call(this)}}})();
//# sourceMappingURL=url_list.map.js